package io;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class OOSDemo {
    public static void main(String[] args) throws IOException {
        String[] otherInfo = {"java圣经", "现在不学更待何时", "月薪上万不是梦"};
        Student zs = new Student("张三", 13, "男性", otherInfo);
        Student ls = new Student("李四", 23, "男性", otherInfo);
        Student ww = new Student("王五", 23, "男性", otherInfo);
        List<Student> s = new ArrayList<>();
        s.add(zs);
        s.add(ls);
        s.add(ww);


        FileOutputStream fos = new FileOutputStream("student.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        for (int i = 0; i < s.size(); i++) {
            oos.writeObject(s.get(i));
            System.out.println(s.get(i));
        }
        oos.close();

        /*        String[] otherInfo = {"来自佳木斯", "热爱詹姆斯", "喜欢吃寿司"};
        Student s = new Student("张三", 12, "男人", otherInfo);
        System.out.println(s);
        FileOutputStream fos = new FileOutputStream("student.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(s);
        oos.close();*/

    }
}
